public class RaDan implements IGameLogic
{
	private State realState;
	private MiniMax miniMax;
	private int maxNoOfCoins;
	private int depth = 12;
	
	public RaDan() { }

	public void initializeGame(int cols, int rows, int playerID) {
		maxNoOfCoins = cols * rows;
		realState = new State(cols, rows, maxNoOfCoins);
		miniMax = new MiniMax(cols, rows, playerID, maxNoOfCoins);
	}

	public Winner gameFinished() {
		return miniMax.terminalTest(realState).winner;
	}

	public void insertCoin(int col, int playerID) {
		realState.insertCoin(col, playerID);
	}

	public int decideNextMove() {
		long start = System.currentTimeMillis();
		int[] alpha = {Integer.MIN_VALUE, -1};
		int[] beta = {Integer.MAX_VALUE, -1};
		int next = miniMax.alphabeta(realState, depth, alpha, beta, true)[1];
		if (System.currentTimeMillis() - start < 500)
			depth++;
		return next;
	}
}